package com.archgeek.java.utils;

import cn.hutool.core.date.DateUtil;
import com.archgeek.java.utils.RetryUtils.CallToRetry;
import org.apache.commons.lang3.RandomUtils;

import java.util.concurrent.TimeUnit;

/**
 * @author pizhihui
 * @date 2023-12-05 10:32
 */
public class RetryUtilsTest {


    public static void main(String[] args) throws Exception {

        CallToRetry retryFuntion = (retry) -> {
//            if (retry == 0) {
                int i = 1 / 0;
//            }
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(10, 20));
            System.out.println(DateUtil.now() + "执行任务,重试次数+" + retry);
        };

        RetryUtils.withRetry(3, 1000, retryFuntion);

        System.out.println(DateUtil.now() + "结束任务.....");

    }

}
